<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class EvalController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        return view('home.eval');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        // dd($request);
        // 评论插入数据库
        $type=DB::table('type')->get()->all();
        $ss=DB::table('product')->inRandomOrder()->take(6)->get()->all();
        $uid = session('homeuser')->id;
        // dd($uid);
        $data = $request->except('_token');
        // dd($data);
        $data['user_id'] = $uid;
        // dd($data);
        $id = DB::table('product_evaluation')->insertGetId($data);

        // $m = DB::table('product_evaluation')->orderBy('id', 'desc')->first();
        // $eid = $m->id;
        // // dd($m->id);
        // $n = DB::table('evaluation_reply')->insertGetId(['evaluation_id' => $eid, 'user_id' => $uid]);
 
        if($id>0){
            return view('eval.evalsuccess',['search'=>$ss,'all'=>$type]);
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //dd($id);
        $db = DB::table('product')->leftjoin('myorder','product.id', '=', 'myorder.product_id')->where('myorder.id',$id)->get();
        //dd($db);
        $type=DB::table('type')->get()->all();
        $ss=DB::table('product')->inRandomOrder()->take(6)->get()->all();
        $links=DB::table('links')->get();
        return view('home.eval',['list'=>$db,
                                'search'=>$ss,
                                'all'=>$type,
                                'links'=>$links]);

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
